package com.prnasia.cloud.spring.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.http.codec.ServerCodecConfigurer;

/**
 * Created by Wen Gao on 2019/4/11.
 */
@SpringBootApplication
@EnableEurekaClient
public class GatewayApp {

    public static void main(String[] args) {
        ServerCodecConfigurer c = null;
        SpringApplication.run(GatewayApp.class, args);
    }

    @Bean
    public RouteLocator myRoute(RouteLocatorBuilder builder) {
        // 使用RouteLocator的Bean进行路由转发，将请求进行处理，最后转发到目标的下游服务
        return builder.routes()
                .route(p -> p
                        .path("/get")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri("http://httpbin.org:80"))
                .route(p -> p
                        .path("/amp/getSendmailConfig")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri("http://172.20.10.99:11000/amp/getSendmailConfig"))
                .build();
    }


}
